package com.system.demo.config;

import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.amqp.core.Binding;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {

    // 定义队列
    @Bean
    public Queue notificationQueue() {
        return new Queue("notificationQueue", true); // Durable Queue
    }

    // 定义交换机
    @Bean
    public TopicExchange topicExchange() {
        return new TopicExchange("notificationExchange");
    }

    // 绑定队列与交换机
    @Bean
    public Binding binding(Queue notificationQueue, TopicExchange topicExchange) {
        return BindingBuilder.bind(notificationQueue).to(topicExchange).with("notification.#");
    }
}
